package neu.soft.service.impl;

import lombok.extern.slf4j.Slf4j;
import neu.soft.entity.DO.Balance;
import neu.soft.exception.AppException;
import neu.soft.exception.AppExceptionCodeMsg;
import neu.soft.mapper.FinancialMapper;
import neu.soft.service.FinancialService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.math.BigDecimal;

/**
 * 到款结账以及付款服务
 */
@Service
@Slf4j
public class FinancialServiceImpl implements FinancialService {

    @Autowired
    FinancialMapper financialMapper;

    @Override
    public void pay(BigDecimal payment) {
        Balance money = financialMapper.getBalance();
        int res = financialMapper.pay(payment,money.getVersion());
        if (res < 1){
            throw new AppException(AppExceptionCodeMsg.YYDZ_JDWGXSB);
        }
    }

    @Override
    public void receipt(BigDecimal accountReceivable) {
        Balance money = financialMapper.getBalance();
        int res = financialMapper.receipt(accountReceivable,money.getVersion());
        if (res < 1){
            throw new AppException(AppExceptionCodeMsg.YYDZ_JDWGXSB);
        }
    }
}
